import Vue from 'vue'
import App from './App.vue'
import router from './router'

//elementUI
import 'element-ui/lib/theme-chalk/index.css';
import ElementUI from 'element-ui';
//将elementUI注册为全局变量
Vue.use(ElementUI);

//axios
import axios from 'axios'
Vue.prototype.$axios = axios

//请求工具类方法
import {postRequest} from './utils/api.js'
import {putRequest} from './utils/api.js'
import {getRequest} from './utils/api.js'
import {deleteRequest} from './utils/api.js';
Vue.prototype.postRequest = postRequest;
Vue.prototype.putRequest = putRequest;
Vue.prototype.getRequest = getRequest;
Vue.prototype.deleteRequest = deleteRequest;


Vue.config.productionTip = false

//过滤器时间格式化
Vue.filter('dataFormat', function (originVal) {
  const dt = new Date(originVal)
  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1 + '').padStart(2, '0')
  const d = (dt.getDate() + '').padStart(2, '0')
 
  const hh = (dt.getHours() + '').padStart(2, '0')
  const mm = (dt.getMinutes() + '').padStart(2, '0')
  const ss = (dt.getSeconds() + '').padStart(2, '0')
  // yyyy-mm-dd hh:mm:ss
  return `${y}年${m}月${d}日 ${hh}:${mm}:${ss}`
})

//导入vuex
import store from '@/store/index.js';

//引入初始化路由方法
import {initMenu} from './utils/menus.js';

//添加路由前置守卫
router.beforeEach((to,from,next)=>{
	if(to.path!='/' && sessionStorage.getItem("user")==null){
		next("/")
	}else{
		if(to.path=="/"){
			next();
		}else{
			//初始化菜单信息
			initMenu(router,store);
			next();
		}
	}
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
